package MethodTest.MethodRecursionTest;

import java.util.Scanner;

/*
使用递归和for循环，编写程序，计算1-n的阶乘
 */
public class RecursionTest3 {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        System.out.println("请输入一个整数");
        int num = s.nextInt();
        System.out.println(jiCheng(num));
        System.out.println(jiChengFor(num));
    }
    //递归就阶乘
    public static int jiCheng(int n){
        if(n == 2){
            return 2;
        }
        return n * jiCheng(n-1);
    }
    //for循环就阶乘
    public static int jiChengFor(int n){
        int chenJi = 1;
        for(int i = n; i > 1; i--){
            chenJi *= i;
        }
        return chenJi;
    }
}
